import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import SlideVerify from 'vue-monoplasty-slide-verify'
import VueParticles from 'vue-particles'
import axios from 'axios'
import requests from '@/api/request'
import { List, Cell, CellGroup } from 'vant'

Vue.use(List)

Vue.use(Cell)
Vue.use(CellGroup)
// reqCategoryList();
Vue.config.productionTip = false
Vue.use(VueParticles)
Vue.use(SlideVerify)
Vue.use(ElementUI)
axios.defaults.withCredentials = true
// axios请求拦截器请求头携带token
axios.interceptors.request.use((config) => {
  if (localStorage.getItem('token')) {
    config.headers.token = localStorage.getItem('token')
    // Access-Control-Allow-Origin
    config.headers['Access-Control-Allow-Origin'] = '*'
  }
  return config
},
err => {
  return Promise.reject(err)
}
)
axios.interceptors.response.use((res) => {
  // Access-Control-Allow-Origin
  res.headers['Access-Control-Allow-Origin'] = '*'
  if (res.data === '') {
    localStorage.removeItem('token')
  }
  return res
}, (error) => {
  return Promise.reject(error)
})
// 设置axios的基础路径
new Vue({
  router,
  store,
  render: h => h(App),
  beforeCreate () {
    // Vue.http.options.xhr = { withCredentials: true }
    Vue.prototype.$bus = this
  }
}).$mount('#app')
